GATE Exam  >  GATE Questions  >   C What does the following fragment of c prog... Start Learning for Free
C What does the following fragment of c program print?
#include
int main()
{
static int GATE[]={100,200,300,400,500};
static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}
int **p = ptr;
ptr++;
printf("%d%d", ptr - p, **ptr};
}
The output of the program is______
  • a)
    1100
  • b)
    150
  • c)
    160
  • d)
    170
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
C What does the following fragment of c program print?#includeint mai...
In order to simplify programs involving complex operations on pointers, we suggest you to draw proper diagrams in order to avoid silly mistakes. Let’s assume that integer is of 4 Bytes and Pointer size is also 4 Bytes.
Let’s assume array a Base address is 1000. Array name actually holds the array base address.
Array A
Let’s assume array p Base address is 2000.
Array P.
Double Pointer ptr Base Address is 3000.
Ptr
Now ptr is actually pointing to the first element of array p. ptr++ will make it point to the next element of array p. Its value will then change to 2004.
One of the Rule of Pointer Arithmetic is that When you subtract two pointers, as long as they point into the same array, the result is the number of elements separating them.
ptr is pointing to the second element and p is pointing to the first element so ptr-p will be equal to 1(Excluding the element to which ptr is pointing).
Now ptr = 2004 →*(2004) = 1000 →*(1000) →100.
Therefore, the final answer is 1100.
View all questions of this test
Explore Courses for GATE exam
C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer?
Question Description
C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer?.
Solutions for C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer?, a detailed solution for C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer? has been provided alongside types of C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice C What does the following fragment of c program print?#includeint main(){static int GATE[]={100,200,300,400,500};static int *ptr = {GATE+2,GATE,GATE+3,GATE+4,GATE+1}int **p = ptr;ptr++;printf("%d%d", ptr - p, **ptr};}The output of the program is______a)1100b)150c)160d)170Correct answer is option 'A'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev